﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;

namespace Lilium.Unity
{
    public static class UnityContainerExtensions
    {
        public static TExtension EnsureExtension<TExtension>(this IUnityContainer unityContainer)
            where TExtension : UnityContainerExtension, new()
        {
            if (unityContainer == null) throw new ArgumentNullException("unityContainer");

            var extension = unityContainer.Configure<TExtension>();
            if (extension == null)
            {
                unityContainer.AddNewExtension<TExtension>();
                return unityContainer.Configure<TExtension>();
            }
            else
                return extension;
        }
    }
}
